using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FireRain : MonoBehaviour
{
    private GameObject player;
    public float speed = 7.0f;

    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        Destroy(this.gameObject, 4);
    }

    void Update()
    {
        transform.position += speed * Time.deltaTime * Vector3.down;
    }

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Player") && player != null)
        {
            Player playerScript = player.GetComponent<Player>();
            if (playerScript != null && !playerScript.isInvulnerable)
            {
                playerScript.TakeDamage(1);
                Destroy(gameObject);
            }
        }
    }
}
